<template>
    <div>
        <el-card>
            <el-table :data="userList" style="width: 100%">
                <el-table-column label="ID" prop="id"> </el-table-column>
                <el-table-column label="账号" prop="email">
                </el-table-column>
				<el-table-column label="性别">
					<template slot-scope="props">
						{{1 === props.row.gender ? '男' : '女'}}
					</template>
                </el-table-column>
				<el-table-column label="姓名" prop="name">
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="180">
                    <template slot-scope="scope">
						<el-button
                            @click="resetUser(scope.row.id)"
                            type="primary"
                            size="small"
                        >
                            重置密码
                        </el-button>
						<el-button
                            @click="delUser(scope.row.id)"
                            type="danger"
                            size="small"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
			<el-pagination
				layout="prev, pager, next"
				@current-change="getlist"
				:total="this.total">
			</el-pagination>
        </el-card>
    </div>
</template>

<script>
import {getUser, resetPassword, delUser} from "network/request.js";
import { Message } from 'element-ui';

export default {
    created() {
        this.getlist();
    },
    data() {
        return {
            userList: [],
			editId: '',
			dialogVisible: false,
			offset: 0,
			total: 0,
        };
    },
    methods: {
        getlist(page) {
			if ('number' === typeof page) {
                this.offset  = 10 * (page - 1);
            } else {
                this.offset = 0;
            }
            const params = {
                url: '/admin/users/get',
                method: 'get',
                data: {
                    offset: this.offset,
                }
            }
			getUser(params).then(res => {
				this.userList = res.content.data;
				this.total = res.content.total;
			});
        },
		resetUser(id) {
			const params = {
				data: {
					user_id: id,
					password: '123456',
				},
				url: '/admin/user/pwd_reset',
				method: 'post',
			};
			resetPassword(params).then(res => {
				this.$alert(`重置成功，密码是123456`, '重置成功', {
					confirmButtonText: '确定',
					type: 'success',
					callback: () => {}
				});
			})
		},
		delUser(id) {
			this.$confirm(`删除后不可恢复，是否确定`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning',

				}).then(() => {
					const params = {
						url: '/admin/user/del',
						method: 'post',
						data: {
							ids: [id],
						},
					};
					delUser(params).then(res => {
						Message.success('删除成功! ');
						this.getlist();
					});
				}).catch(() => {

				});
			
        },
        
    },
};
</script>

<style lang="scss" scoped>
</style>